using System.Collections.ObjectModel;
using System.Windows;
using Ch13CardLib.entity;
using Ch13CardLib.enums;
using System.ComponentModel;
using KarliCardsGui.constants;

namespace KarliCardsGui.ViewModels
{
    public class MainViewModel
    {
        public ObservableCollection<CardViewModel> Cards { get; } = new ObservableCollection<CardViewModel>();

        public MainViewModel()
        {
            InitializeCards();
        }

        private void InitializeCards()
        {
            // 创建一副新牌
            Deck deck = new Deck();
            deck.Shuffle();

            // 将52张牌添加到界面上
            for (int i = 0; i < deck.CardList.Count; i++)
            {
                Card card = deck.GetCard(i);
                CardViewModel cardVM = new CardViewModel
                {
                    Suit = card.Suit,
                    Rank = card.Rank,
                    IsFaceUp = false,
                    XPosition = Constants.CardStackPositionX,
                    YPosition = Constants.CardStackPositionY + i * Constants.CardStackOffsetY,
                    ZIndex = i
                };
                Cards.Add(cardVM);
            }
        }

        public void UpdateCardPosition(CardViewModel card)
        {
            int index = Cards.Count;
            card.XPosition = 20;  // 固定X位置
            card.YPosition = 20 + (index * 10);  // 每张牌往下偏移10个单位
            card.ZIndex = index;
        }
    }
}